Vue Component 您所在的位置:网站首页 fullcalendar vue文档 Vue Component

Vue Component

2023-03-24 04:43| 来源: 网络整理| 查看: 265

FullCalendar seamlessly integrates with the Vue JavaScript framework. It provides a component that exactly matches the functionality of FullCalendar’s standard API.

This package is released under an MIT license, the same license the standard version of FullCalendar uses. Useful links:

Browse the Github repo (please star it!) Bug report instructions Example project leveraging Webpack and Sass (the code in this guide loosely follows it) Runnable project in a code playground

This guide does not go into depth about initializing a Vue project. Please consult the aforementioned example/runnable projects for that.

The first step is to install the FullCalendar-related dependencies. You’ll need the Vue adapter, the core package, and any additional plugins you plan to use:

npm install --save @fullcalendar/vue @fullcalendar/core @fullcalendar/daygrid @fullcalendar/interaction

You may then begin to write a parent component that leverages the component (DemoApp.vue):

import FullCalendar from '@fullcalendar/vue' import dayGridPlugin from '@fullcalendar/daygrid' import interactionPlugin from '@fullcalendar/interaction'; export default { components: { FullCalendar // make the tag available }, data() { return { calendarPlugins: [ dayGridPlugin, interactionPlugin ] } } }

Notice how you must define the plugins in the data method, and then pass them into the component. This is the only way!

CSS

You must manually include the stylesheets for FullCalendar’s core and plugins. Assuming you have Sass set up, add a style block in the same .vue file:

@import '~@fullcalendar/core/main.css'; @import '~@fullcalendar/daygrid/main.css';

The prefixed ~ tells Sass to look in the node_modules directory.

Props

The component is equipped with all of FullCalendar’s options! Just pass them in as props. Please be aware of when to prefix : (otherwise known as v-bind:) to the prop names. If you need a bound JavaScript expression, use :. Otherwise, use a normal attribute. Example:

Emitted Events

A listener can be passed into a Vue component that will be called when something happens. For example, the dateClick handler is called whenever the user clicks on a date. In order for this callback to fire, you must load the interaction plugin. If you are using an ES6 build system. The way you pass these into the component is different than props:

They are prefixed with @ (otherwise known as v-on:). Then, in the JavaScript, write your handler method:

methods: { handleDateClick(arg) { alert(arg.date) } }

Don’t mix up when to use props versus events! For help deciding which is which, consult the giant list of props and events in the connector’s source code.

Accessing FullCalendar’s API

Hopefully you won’t need to do it often, but sometimes it’s useful to access the underlying Calendar object for raw data and methods.

This is especially useful for controlling the current date. The defaultDate prop will set the initial date of the calendar, but to change it after that, you’ll need to rely on the date navigation methods.

To do something like this, you’ll need to get ahold of the component’s ref (short for “reference”). In the template:

Once you have the ref, you can get the underlying Calendar object via the getApi method:

let calendarApi = this.$refs.fullCalendar.getApi() calendarApi.next() Kebab-case in Markup

Some people prefer to write component names and prop names in kebab-case when writing markup. This will work fine:

Notice how property values must remain in their original case.

Scheduler

How do you use FullCalendar Scheduler’s premium plugins with Vue? They are no different than any other plugin. Just follow the same instructions as you did dayGridPlugin in the above example. Also, make sure to include your schedulerLicenseKey:

import FullCalendar from '@fullcalendar/vue' import resourceTimelinePlugin from '@fullcalendar/resource-timeline' export default { components: { FullCalendar }, data() { return { calendarPlugins: [ resourceTimelinePlugin ] } } } @import '~@fullcalendar/core/main.css'; @import '~@fullcalendar/timeline/main.css'; @import '~@fullcalendar/resource-timeline/main.css';


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有